package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ControlStyle;
import com.ruoyi.system.service.IControlStyleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 控件样式Controller
 * 
 * @author ruoyi
 * @date 2024-02-26
 */
@RestController
@RequestMapping("/system/style")
public class ControlStyleController extends BaseController
{
    @Autowired
    private IControlStyleService controlStyleService;

    /**
     * 查询控件样式列表
     */
    @PreAuthorize("@ss.hasPermi('system:style:list')")
    @GetMapping("/list")
    public TableDataInfo list(ControlStyle controlStyle)
    {
        startPage();
        List<ControlStyle> list = controlStyleService.selectControlStyleList(controlStyle);
        return getDataTable(list);
    }

    /**
     * 导出控件样式列表
     */
    @PreAuthorize("@ss.hasPermi('system:style:export')")
    @Log(title = "控件样式", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ControlStyle controlStyle)
    {
        List<ControlStyle> list = controlStyleService.selectControlStyleList(controlStyle);
        ExcelUtil<ControlStyle> util = new ExcelUtil<ControlStyle>(ControlStyle.class);
        util.exportExcel(response, list, "控件样式数据");
    }

    /**
     * 获取控件样式详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:style:query')")
    @GetMapping(value = "/{styleId}")
    public AjaxResult getInfo(@PathVariable("styleId") Long styleId)
    {
        return success(controlStyleService.selectControlStyleByStyleId(styleId));
    }

    /**
     * 新增控件样式
     */
    @PreAuthorize("@ss.hasPermi('system:style:add')")
    @Log(title = "控件样式", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ControlStyle controlStyle)
    {
        return toAjax(controlStyleService.insertControlStyle(controlStyle));
    }

    /**
     * 修改控件样式
     */
    @PreAuthorize("@ss.hasPermi('system:style:edit')")
    @Log(title = "控件样式", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ControlStyle controlStyle)
    {
        return toAjax(controlStyleService.updateControlStyle(controlStyle));
    }

    /**
     * 删除控件样式
     */
    @PreAuthorize("@ss.hasPermi('system:style:remove')")
    @Log(title = "控件样式", businessType = BusinessType.DELETE)
	@DeleteMapping("/{styleIds}")
    public AjaxResult remove(@PathVariable Long[] styleIds)
    {
        return toAjax(controlStyleService.deleteControlStyleByStyleIds(styleIds));
    }
}
